//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.doc.server.impl;

import com.farm.authority.domain.Organization;
import com.farm.authority.domain.Post;
import com.farm.authority.service.OrganizationServiceInter;
import com.farm.authority.service.UserServiceInter;
import com.farm.core.auth.domain.LoginUser;
import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DBSort;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.query.DataQuerys;
import com.farm.core.sql.query.DataQuery.CACHE_UNIT;
import com.farm.core.sql.result.DataResult;
import com.farm.core.time.TimeTool;
import com.farm.doc.dao.FarmDocDaoInter;
import com.farm.doc.dao.FarmDocenjoyDaoInter;
import com.farm.doc.dao.FarmDocfileDaoInter;
import com.farm.doc.dao.FarmDocgroupDaoInter;
import com.farm.doc.dao.FarmDocmessageDaoInter;
import com.farm.doc.dao.FarmDocruninfoDaoInter;
import com.farm.doc.dao.FarmDocruninfoDetailDaoInter;
import com.farm.doc.dao.FarmDoctextDaoInter;
import com.farm.doc.dao.FarmDoctypeDaoInter;
import com.farm.doc.dao.FarmRfDoctextfileDaoInter;
import com.farm.doc.dao.FarmRfDoctypeDaoInter;
import com.farm.doc.dao.FarmtopDaoInter;
import com.farm.doc.dao.TypedemoDaoInter;
import com.farm.doc.domain.FarmDoctype;
import com.farm.doc.domain.ex.TypeBrief;
import com.farm.doc.server.FarmDocOperateRightInter;
import com.farm.doc.server.FarmDocTypeInter;
import com.farm.doc.server.FarmFileManagerInter;
import com.farm.doc.server.plus.FarmTypePopServerInter;
import com.farm.doc.server.plus.domain.Doctypepop;
import com.farm.parameter.FarmParameterService;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 文档分类管理
 * @author yang_
 *
 */
@Service
public class FarmDocTypeManagerImpl implements FarmDocTypeInter {
    @Resource
    private FarmDocDaoInter farmDocDao;
    @Resource
    private FarmDocfileDaoInter farmDocfileDao;
    @Resource
    private FarmDoctextDaoInter farmDoctextDao;
    @Resource
    private FarmRfDoctextfileDaoInter farmRfDoctextfileDao;
    @Resource
    private FarmRfDoctypeDaoInter farmRfDoctypeDao;
    @Resource
    private FarmDoctypeDaoInter farmDoctypeDao;
    @Resource
    private FarmDocmessageDaoInter farmDocmessageDao;
    @Resource
    private FarmDocruninfoDaoInter farmDocruninfoDao;
    @Resource
    private FarmDocenjoyDaoInter farmDocenjoyDao;
    @Resource
    private FarmDocOperateRightInter farmDocOperate;
    @Resource
    private FarmDocgroupDaoInter farmDocgroupDao;
    @Resource
    private FarmDocruninfoDetailDaoInter farmDocruninfoDetailDao;
    @Resource
    private FarmFileManagerInter farmFileServer;
    @Resource
    private FarmtopDaoInter farmtopDaoImpl;
    @Resource
    private OrganizationServiceInter organizationServiceImpl;
    @Resource
    private FarmTypePopServerInter farmTypePopServerImpl;
    @Resource
    private UserServiceInter userServiceImpl;
    @Resource
    private TypedemoDaoInter typedemoDaoImpl;
    private static final Logger log = Logger.getLogger(FarmDocTypeManagerImpl.class);

    public FarmDocTypeManagerImpl() {
    }

    @Transactional
    public FarmDoctype insertType(FarmDoctype entity, LoginUser user) {
        entity.setCtime(TimeTool.getTimeDate14());
        entity.setEtime(TimeTool.getTimeDate14());
        entity.setCuser(user.getId());
        entity.setEuser(user.getId());
        entity.setCusername(user.getName());
        entity.setEusername(user.getName());
        entity.setReadpop("0");
        entity.setDocnum(Integer.valueOf(0));
        entity.setQuestionnum(Integer.valueOf(0));
        entity.setTagsnum(Integer.valueOf(0));
        entity.setWritepop("0");
        entity.setAuditpop("0");
        if (entity.getParentid() == null || entity.getParentid().trim().length() <= 0) {
            entity.setParentid("NONE");
        }

        entity.setTreecode("NONE");
        entity = this.farmDoctypeDao.insertEntity(entity);
        if (entity.getParentid().equals("NONE")) {
            entity.setTreecode(entity.getId());
        } else {
            entity.setTreecode(this.farmDoctypeDao.getEntity(entity.getParentid()).getTreecode() + entity.getId());
        }

        FarmDoctype parentType = this.farmDoctypeDao.getEntity(entity.getParentid());
        if (parentType != null) {
            if (!parentType.getAuditpop().equals("0")) {
                entity.setAuditpop("2");
            }

            if (!parentType.getReadpop().equals("0")) {
                entity.setReadpop("2");
            }

            if (!parentType.getWritepop().equals("0")) {
                entity.setWritepop("2");
            }
        }

        return this.farmDoctypeDao.insertEntity(entity);
    }

    @Transactional
    public FarmDoctype editType(FarmDoctype entity, LoginUser user) {
        FarmDoctype entity2 = this.farmDoctypeDao.getEntity(entity.getId());
        entity2.setEtime(TimeTool.getTimeDate14());
        entity2.setEuser(user.getId());
        entity2.setEusername(user.getName());
        entity2.setName(entity.getName());
        entity2.setTypemod(entity.getTypemod());
        entity2.setContentmod(entity.getContentmod());
        entity2.setSort(entity.getSort());
        entity2.setTags(entity.getTags());
        entity2.setType(entity.getType());
        entity2.setMetatitle(entity.getMetatitle());
        entity2.setMetakey(entity.getMetakey());
        entity2.setMetacontent(entity.getMetacontent());
        entity2.setLinkurl(entity.getLinkurl());
        entity2.setPcontent(entity.getPcontent());
        entity2.setPstate(entity.getPstate());
        FarmDoctype parentType = this.farmDoctypeDao.getEntity(entity2.getParentid());
        if (parentType != null) {
            if (!parentType.getAuditpop().equals("0")) {
                entity2.setAuditpop("2");
            }

            if (!parentType.getReadpop().equals("0")) {
                entity2.setReadpop("2");
            }

            if (!parentType.getWritepop().equals("0")) {
                entity2.setWritepop("2");
            }
        }

        this.farmDoctypeDao.editEntity(entity2);
        return entity2;
    }

    @Transactional
    public void deleteType(String typeId, LoginUser user) {
        if (this.getAllSubNode(typeId).size() > 1) {
            throw new RuntimeException("请先该删除分类的子分类！");
        } else {
            List<DBRule> rulesDelType = new ArrayList();
            rulesDelType.add(new DBRule("TYPEID", typeId, "="));
            this.farmRfDoctypeDao.deleteEntitys(rulesDelType);
            this.typedemoDaoImpl.deleteEntitys(rulesDelType);
            this.farmTypePopServerImpl.delTypePop(typeId);
            this.farmDoctypeDao.deleteEntity(this.farmDoctypeDao.getEntity(typeId));
        }
    }

    @Transactional
    public FarmDoctype getType(String id) {
        return id == null ? null : this.farmDoctypeDao.getEntity(id);
    }

    @Transactional
    public List<FarmDoctype> getTypeAllParent(String typeid) {
        String id = typeid;
        ArrayList types = new ArrayList();

        while(id != null) {
            FarmDoctype centity = this.farmDoctypeDao.getEntity(id);
            if (centity != null && centity.getParentid() != null && centity.getParentid().trim().length() > 0) {
                id = centity.getParentid();
            } else {
                id = null;
            }

            if (centity != null) {
                types.add(centity);
            }
        }

        Collections.reverse(types);
        return types;
    }

    @Transactional
    public List<TypeBrief> getTypeInfos(LoginUser user, String parentId) {
        DataQuerys.wipeVirus(parentId);
        DataQuery query = null;
        query = DataQuery.init(query, "(SELECT a.NAME as NAME,a.readpop as READPOP,a.WRITEPOP as WRITEPOP, a.ID as ID, a.PARENTID as PARENTID, A.DOCNUM AS NUM,A.QUESTIONNUM as QUESTIONNUM FROM farm_doctype AS a LEFT JOIN farm_doctype AS b ON b.ID = a.PARENTID WHERE 1 = 1 AND (a.TYPE = '1' OR a.TYPE = '3') AND a.PSTATE = '1' and (a.PARENTID='" + parentId + "' or b.PARENTID='" + parentId + "') ORDER BY a.SORT ASC) AS e", "NAME,ID,PARENTID,NUM,READPOP,WRITEPOP,QUESTIONNUM");
        query.setDistinct(true);
        String typeids = null;
        Iterator var6 = this.getUserReadTypeIds(user).iterator();

        while(var6.hasNext()) {
            String id = (String)var6.next();
            if (typeids == null) {
                typeids = "'" + id + "'";
            } else {
                typeids = typeids + "," + "'" + id + "'";
            }
        }

        if (user != null) {
            query.addSqlRule("and (READPOP='0' or (READPOP!='0' and ID in (" + typeids + ")))");
        } else {
            query.addSqlRule("and READPOP='0'");
        }

        query.setPagesize(1000);
        query.setNoCount();
        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

        try {
            return query.search().getObjectList(TypeBrief.class);
        } catch (SQLException var7) {
            log.error(var7.toString());
            return new ArrayList();
        }
    }

    @Transactional
    public DataResult getTypeDocs(LoginUser user, String typeid, int pagesize, int currentPage) {
        DataQuerys.wipeVirus(typeid);
        String userid = user == null ? "none" : user.getId();
        String typeids = null;
        Iterator var8 = this.getUserReadTypeIds(user).iterator();

        while(var8.hasNext()) {
            String id = (String)var8.next();
            if (typeids == null) {
                typeids = "'" + id + "'";
            } else {
                typeids = typeids + "," + "'" + id + "'";
            }
        }

        FarmDoctype type = this.getType(typeid);
        DataQuery query = DataQuery.init(new DataQuery(), "farm_doc a LEFT JOIN farm_docruninfo b ON a.RUNINFOID=b.ID LEFT JOIN farm_rf_doctype c ON c.DOCID=a.ID LEFT JOIN farm_doctype d ON d.ID=c.TYPEID LEFT JOIN ALONE_AUTH_USER e ON e.ID = a.CUSER", "a.ID as DOCID,a.DOMTYPE as DOMTYPE,a.TITLE AS title,a.DOCDESCRIBE AS DOCDESCRIBE,a.AUTHOR AS AUTHOR,a.PUBTIME AS PUBTIME,a.TAGKEY AS TAGKEY ,a.IMGID AS IMGID,b.VISITNUM AS VISITNUM,b.PRAISEYES AS PRAISEYES,b.PRAISENO AS PRAISENO,b.HOTNUM AS HOTNUM,b.EVALUATE as EVALUATE,b.ANSWERINGNUM as ANSWERINGNUM,d.id as TYPEID,d.NAME AS TYPENAME, e.ID as USERID, e.NAME as USERNAME, e.IMGID as USERIMGID");
        query.addSort(new DBSort("a.etime", "desc"));
        query.setCurrentPage(currentPage);
        query.addRule(new DBRule("a.STATE", "1", "="));
        query.addRule(new DBRule("DOMTYPE", "4", "!="));
        if (type != null) {
            query.addRule(new DBRule("d.TREECODE", type.getTreecode(), "like-"));
        }

        if (user != null) {
            query.addSqlRule("and (d.READPOP='0' or (d.READPOP!='0' and d.id in (" + typeids + ")))");
        } else {
            query.addSqlRule("and d.READPOP='0'");
        }

        query.addSqlRule("and (a.READPOP='1' or a.CUSER='" + userid + "' OR (a.READPOP = '2' AND 0 < (SELECT count(e.ID) FROM farm_docgroup_user e WHERE e.PSTATE = 1 AND e.GROUPID = a.DOCGROUPID AND e.CUSER = '" + userid + "')))");
        query.setPagesize(pagesize);
        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);
        DataResult docs = null;

        try {
            docs = query.search();
        } catch (SQLException var12) {
            log.error(var12.toString());
            return DataResult.getInstance();
        }

        Iterator var11 = docs.getResultList().iterator();

        while(true) {
            while(var11.hasNext()) {
                Map<String, Object> map = (Map)var11.next();
                if (map.get("USERIMGID") != null && !map.get("USERIMGID").toString().isEmpty()) {
                    map.put("PHOTOURL", this.farmFileServer.getFileURL(map.get("USERIMGID").toString()));
                } else {
                    map.put("PHOTOURL", this.farmFileServer.getFileURL("NONE"));
                }

                if (map.get("IMGID") != null && !map.get("IMGID").toString().isEmpty()) {
                    map.put("IMGURL", this.farmFileServer.getFileURL(map.get("IMGID").toString()));
                } else {
                    map.put("IMGURL", (Object)null);
                }
            }

            return docs;
        }
    }

    @Transactional
    public List<Doctypepop> getTypePops(String typeid) {
        List<Doctypepop> doctypepops = new ArrayList();
        Iterator var4 = this.getTypeAllParent(typeid).iterator();

        while(var4.hasNext()) {
            FarmDoctype type = (FarmDoctype)var4.next();
            this.farmTypePopServerImpl.getTypePopsHandle(doctypepops, type.getReadpop(), type.getWritepop(), type.getAuditpop(), type.getId());
        }

        return doctypepops;
    }

    @Transactional
    public List<FarmDoctype> getAllSubNode(String typeid) {
        DataQuery query = DataQuery.getInstance(1, "NAME,TYPEMOD,CONTENTMOD,SORT,TYPE,METATITLE,METAKEY,METACONTENT,LINKURL,ID,TAGS,CTIME,ETIME,CUSERNAME,CUSER,EUSERNAME,EUSER,PCONTENT,PSTATE,PARENTID,TREECODE,READPOP,WRITEPOP,AUDITPOP,DOCNUM,QUESTIONNUM,TAGSNUM", "FARM_DOCTYPE");
        query.addRule(new DBRule("TREECODE", this.farmDoctypeDao.getEntity(typeid).getTreecode(), "like-"));
        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);
        query.setPagesize(1000);

        try {
            return query.search().getObjectList(FarmDoctype.class);
        } catch (SQLException var4) {
            throw new RuntimeException(var4);
        }
    }

    @Transactional
    public List<TypeBrief> getPubTypes() {
        DataQuery query = DataQuery.init(new DataQuery(), "(SELECT a.NAME as NAME, a.ID as ID, a.PARENTID as PARENTID, A.DOCNUM AS NUM FROM farm_doctype AS a WHERE 1 = 1 AND (TYPE = '1' OR TYPE = '3') AND PSTATE = '1' AND READPOP='0' ORDER BY SORT ASC) AS e", "NAME,ID,PARENTID,NUM");
        query.setPagesize(1000);
        query.setNoCount();
        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

        try {
            return query.search().getObjectList(TypeBrief.class);
        } catch (SQLException var3) {
            log.error(var3.toString());
            return new ArrayList();
        }
    }

    @Transactional
    public List<String> getPubTypeIds() {
        List<String> list = new ArrayList();
        Iterator var3 = this.getPubTypes().iterator();

        while(var3.hasNext()) {
            TypeBrief type = (TypeBrief)var3.next();
            list.add(type.getId());
        }

        return list;
    }

    @Transactional
    public List<TypeBrief> getTypes() {
        DataQuery query = DataQuery.init(new DataQuery(), "FARM_DOCTYPE", "ID,NAME,TYPE,PARENTID,READPOP,WRITEPOP,AUDITPOP");
        query.setPagesize(10000);
        query.setNoCount();

        try {
            return query.search().getObjectList(TypeBrief.class);
        } catch (SQLException var3) {
            log.error(var3.toString());
            return new ArrayList();
        }
    }

    public List<TypeBrief> getPopFqaTypesForReadDoc(LoginUser user) {
        DataQuery query = DataQuery.init(new DataQuery(), "(SELECT a.NAME as NAME,a.SORT as SORT, a.ID as ID, a.READPOP as READPOP,a.WRITEPOP AS WRITEPOP, a.AUDITPOP AS AUDITPOP, a.PARENTID AS PARENTID, A.QUESTIONNUM AS NUM,f.oid as OID,f.FUNTYPE as FUNTYPE FROM farm_doctype AS a left join FARM_DOCTYPE_POP as f on f.TYPEID=a.ID WHERE 1 = 1 AND (TYPE = '1' OR TYPE = '3') AND PSTATE = '1' ) AS e", "NAME,ID,PARENTID,NUM,OID,READPOP,AUDITPOP,WRITEPOP,FUNTYPE,SORT");
        query.setPagesize(10000);
        query.setNoCount();
        if (user != null) {
            query.addSqlRule("and ('1'!='" + user.getId() + "' )");
        }

        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);
        query.addSort(new DBSort("SORT", "ASC"));

        try {
            DataResult result = query.search();
            return this.getTypeLimit(result, user, "1");
        } catch (SQLException var4) {
            log.error(var4.toString());
            return new ArrayList();
        }
    }

    public List<TypeBrief> getPopTypesForReadDoc(LoginUser user) {
        DataQuery query = DataQuery.init(new DataQuery(), "(SELECT a.NAME as NAME,a.SORT as SORT, a.ID as ID, a.READPOP as READPOP,a.WRITEPOP AS WRITEPOP, a.AUDITPOP AS AUDITPOP, a.PARENTID AS PARENTID, A.DOCNUM AS NUM,a.QUESTIONNUM AS QUESTIONNUM,f.oid as OID,f.FUNTYPE as FUNTYPE FROM farm_doctype AS a left join FARM_DOCTYPE_POP as f on f.TYPEID=a.ID WHERE 1 = 1 AND (TYPE = '1' OR TYPE = '3') AND PSTATE = '1' ) AS e", "NAME,ID,PARENTID,NUM,QUESTIONNUM,OID,READPOP,AUDITPOP,WRITEPOP,FUNTYPE,SORT");
        query.setPagesize(10000);
        query.setNoCount();
        if (user != null) {
            query.addSqlRule("and ('1'!='" + user.getId() + "' )");
        }

        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);
        query.addSort(new DBSort("SORT", "ASC"));

        try {
            DataResult result = query.search();
            return this.getTypeLimit(result, user, "1");
        } catch (SQLException var4) {
            log.error(var4.toString());
            return new ArrayList();
        }
    }

    public List<TypeBrief> getTypesForWriteDoc(LoginUser user) {
        DataQuery query = DataQuery.init(new DataQuery(), "(SELECT a.NAME as NAME, a.ID as ID,a.TYPE as type, a.READPOP as READPOP,a.WRITEPOP AS WRITEPOP, a.AUDITPOP AS AUDITPOP, a.PARENTID AS PARENTID, A.DOCNUM AS NUM,f.oid as OID,f.FUNTYPE as FUNTYPE FROM farm_doctype AS a left join FARM_DOCTYPE_POP as f on f.TYPEID=a.ID WHERE   (TYPE = '1' OR TYPE = '3') AND PSTATE = '1' ORDER BY SORT ASC) AS e", "NAME,ID,PARENTID,NUM,OID,READPOP,TYPE,AUDITPOP,WRITEPOP,FUNTYPE");
        query.setPagesize(10000);
        query.setNoCount();
        query.setDistinct(true);
        if (user != null) {
            query.addSqlRule("and ('1'!='" + user.getId() + "' )");
        }

        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

        try {
            DataResult result = query.search();
            return this.getTypeLimit(result, user, "2");
        } catch (SQLException var4) {
            log.error(var4.toString());
            return new ArrayList();
        }
    }

    public List<TypeBrief> getFqaTypesForWriteDoc(LoginUser user) {
        DataQuery query = DataQuery.init(new DataQuery(), "(SELECT a.NAME as NAME, a.ID as ID,a.TYPE as type, a.READPOP as READPOP,a.WRITEPOP AS WRITEPOP, a.AUDITPOP AS AUDITPOP, a.PARENTID AS PARENTID, A.QUESTIONNUM AS NUM,f.oid as OID,f.FUNTYPE as FUNTYPE FROM farm_doctype AS a left join FARM_DOCTYPE_POP as f on f.TYPEID=a.ID WHERE   (TYPE = '1' OR TYPE = '3') AND PSTATE = '1' ORDER BY SORT ASC) AS e", "NAME,ID,PARENTID,NUM,OID,READPOP,TYPE,AUDITPOP,WRITEPOP,FUNTYPE");
        query.setPagesize(10000);
        query.setNoCount();
        query.setDistinct(true);
        if (user != null) {
            query.addSqlRule("and ('1'!='" + user.getId() + "' )");
        }

        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

        try {
            DataResult result = query.search();
            return this.getTypeLimit(result, user, "2");
        } catch (SQLException var4) {
            log.error(var4.toString());
            return new ArrayList();
        }
    }

    private List<TypeBrief> getTypeLimit(DataResult result, LoginUser user, String type) {
        Organization org = null;
        List<Post> posts = null;
        if (user != null) {
            org = this.userServiceImpl.getUserOrganization(user.getId());
            posts = this.userServiceImpl.getPost(user.getId());
        }

        Set<String> idset = new HashSet();
        List<Map<String, Object>> newResult = new ArrayList();
        Iterator var9 = result.getResultList().iterator();

        while(true) {
            while(true) {
                Map node;
                String marktitle;
                do {
                    do {
                        while(true) {
                            do {
                                if (!var9.hasNext()) {
                                    result.setResultList(newResult);
                                    return result.getObjectList(TypeBrief.class);
                                }

                                node = (Map)var9.next();
                            } while(idset.contains((String)node.get("ID")));

                            marktitle = null;
                            if (type.equals("1")) {
                                marktitle = "READPOP";
                            }

                            if (type.equals("2")) {
                                marktitle = "WRITEPOP";
                            }

                            if (!node.get(marktitle).equals("0") && !node.get(marktitle).equals("2")) {
                                break;
                            }

                            newResult.add(node);
                            idset.add((String)node.get("ID"));
                        }
                    } while(!node.get(marktitle).equals("1"));
                } while(user == null);

                if (node.get("OID").equals(user.getId()) && node.get("FUNTYPE").equals(type)) {
                    newResult.add(node);
                    idset.add((String)node.get("ID"));
                } else if (org != null && org.getTreecode().indexOf((String)node.get("OID")) >= 0 && node.get("FUNTYPE").equals(type)) {
                    newResult.add(node);
                    idset.add((String)node.get("ID"));
                } else if (posts != null) {
                    boolean isHavePop = false;
                    Iterator var13 = posts.iterator();

                    while(var13.hasNext()) {
                        Post post = (Post)var13.next();
                        if (node.get("OID").equals(post.getId()) && node.get("FUNTYPE").equals(type)) {
                            isHavePop = true;
                            break;
                        }
                    }

                    if (isHavePop) {
                        newResult.add(node);
                        idset.add((String)node.get("ID"));
                    }
                }
            }
        }
    }

    @Transactional
    public List<String> getUserReadTypeIds(LoginUser user) {
        if (user == null) {
            return new ArrayList();
        } else {
            List<String> ids = new ArrayList();
            Set<String> idset = new HashSet();
            Organization org = null;
            List<Post> posts = null;
            String postSql = "";
            if (user != null) {
                org = this.userServiceImpl.getUserOrganization(user.getId());
                posts = this.userServiceImpl.getPost(user.getId());
            }

            if (posts != null) {
                Iterator var8 = posts.iterator();

                while(var8.hasNext()) {
                    Post post = (Post)var8.next();
                    if (postSql.equals("")) {
                        postSql = " or OID='" + post.getId() + "'";
                    } else {
                        postSql = postSql + " or OID='" + post.getId() + "'";
                    }
                }
            }

            DataQuery query = DataQuery.getInstance("1", "TYPEID,ID", "FARM_DOCTYPE_POP");
            query.setPagesize(1000);
            query.setNoCount();
            query.addSqlRule("and FUNTYPE='1' ");
            query.addSqlRule("and (OID ='" + user.getId() + "' or OID ='" + (org == null ? "none" : org.getId()) + "'" + postSql + ")");
            query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

            try {
                Iterator var9 = query.search().getResultList().iterator();

                while(var9.hasNext()) {
                    Map<String, Object> node = (Map)var9.next();
                    List<FarmDoctype> list = this.getAllSubNode((String)node.get("TYPEID"));
                    Iterator var12 = list.iterator();

                    while(var12.hasNext()) {
                        FarmDoctype one = (FarmDoctype)var12.next();
                        idset.add(one.getId());
                    }
                }
            } catch (SQLException var13) {
                var13.printStackTrace();
                return new ArrayList();
            }

            Iterator var15 = idset.iterator();

            while(var15.hasNext()) {
                String typeid = (String)var15.next();
                ids.add(typeid);
            }

            return ids;
        }
    }

    @Transactional
    public List<String> getUserAuditTypeIds(String userid) {
        DataQuerys.wipeVirus(userid);
        if (userid == null) {
            return new ArrayList();
        } else {
            List<String> ids = new ArrayList();
            Set<String> idset = new HashSet();
            Organization org = null;
            String orgids = null;
            List<Post> posts = null;
            String postSql = "";
            Iterator var9;
            if (userid != null) {
                org = this.userServiceImpl.getUserOrganization(userid);
                if (org != null) {
                    var9 = this.organizationServiceImpl.getParentOrgs(org.getId()).iterator();

                    while(var9.hasNext()) {
                        Organization node = (Organization)var9.next();
                        if (orgids == null) {
                            orgids = "'" + node.getId() + "'";
                        } else {
                            orgids = orgids + ",'" + node.getId() + "'";
                        }
                    }
                }

                posts = this.userServiceImpl.getPost(userid);
            }

            if (posts != null) {
                var9 = posts.iterator();

                while(var9.hasNext()) {
                    Post post = (Post)var9.next();
                    if (postSql.equals("")) {
                        postSql = " or OID='" + post.getId() + "'";
                    } else {
                        postSql = postSql + " or OID='" + post.getId() + "'";
                    }
                }
            }

            DataQuery query = DataQuery.getInstance("1", "TYPEID,ID", "FARM_DOCTYPE_POP");
            query.addSqlRule("and FUNTYPE='3' ");
            query.addSqlRule("and (OID ='" + userid + "' " + (orgids == null ? "" : "or OID in (" + orgids + ")") + postSql + ")");

            try {
                Iterator var10 = query.search().getResultList().iterator();

                while(var10.hasNext()) {
                    Map<String, Object> node = (Map)var10.next();
                    List<FarmDoctype> list = this.getAllSubNode((String)node.get("TYPEID"));
                    Iterator var13 = list.iterator();

                    while(var13.hasNext()) {
                        FarmDoctype one = (FarmDoctype)var13.next();
                        idset.add(one.getId());
                    }
                }
            } catch (SQLException var14) {
                var14.printStackTrace();
                return new ArrayList();
            }

            Iterator var16 = idset.iterator();

            while(var16.hasNext()) {
                String typeid = (String)var16.next();
                ids.add(typeid);
            }

            return ids;
        }
    }

    public List<String> getPopTypeAudtUserIds(String typeid) {
        List<String> ids = new ArrayList();
        Iterator var4 = this.getTypePops(typeid).iterator();

        while(true) {
            Doctypepop pop;
            List users;
            String userid;
            Iterator var7;
            do {
                do {
                    if (!var4.hasNext()) {
                        return ids;
                    }

                    pop = (Doctypepop)var4.next();
                } while(!pop.getFuntype().equals("3"));

                if (pop.getPoptype().equals("1")) {
                    ids.add(pop.getOid());
                }

                if (pop.getPoptype().equals("2")) {
                    users = this.organizationServiceImpl.getOrgUsers(pop.getOid());
                    var7 = users.iterator();

                    while(var7.hasNext()) {
                        userid = (String)var7.next();
                        ids.add(userid);
                    }
                }
            } while(!pop.getPoptype().equals("3"));

            users = this.organizationServiceImpl.getPostUser(pop.getOid());
            var7 = users.iterator();

            while(var7.hasNext()) {
                userid = (String)var7.next();
                ids.add(userid);
            }
        }
    }

    @Transactional
    public List<String> getTypesForUserRead(LoginUser user) {
        List<Map<String, Object>> pubTypes = null;
        List<String> types = new ArrayList();
        DataQuery query = DataQuery.getInstance(1, "ID,NAME", "FARM_DOCTYPE").setPagesize(10000);
        query.addRule(new DBRule("READPOP", "0", "="));
        query.setNoCount();
        query.setCache(Integer.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.brief")).intValue(), CACHE_UNIT.second);

        try {
            pubTypes = query.search().getResultList();
        } catch (SQLException var7) {
            throw new RuntimeException(var7);
        }

        Iterator var6 = pubTypes.iterator();

        while(var6.hasNext()) {
            Map<String, Object> node = (Map)var6.next();
            types.add((String)node.get("ID"));
        }

        if (user != null) {
            List<String> userTypes = this.getUserReadTypeIds(user);
            if (userTypes != null) {
                types.addAll(userTypes);
            }
        }

        return types;
    }

    @Transactional
    public void refreshDocNum(String typeid) {
        List<FarmDoctype> types = this.getTypeAllParent(typeid);
        Iterator var4 = types.iterator();

        while(var4.hasNext()) {
            FarmDoctype type = (FarmDoctype)var4.next();
            type.setDocnum(this.farmDoctypeDao.getTypeDocsNum(type.getId()));
            this.farmDoctypeDao.editEntity(type);
        }

    }
}
